<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" class="el-form">
      <el-form-item label="用户名" prop="loginname">
        <el-input v-model="ruleForm.loginname"></el-input>
      </el-form-item>
      <el-form-item label="电话" >
        <el-input v-model="ruleForm.phone"></el-input>
      </el-form-item>
      <el-form-item label="用户类型" >
        <el-input v-model="ruleForm.userclassify===1?'管理员':'普通用户'" disabled></el-input>
      </el-form-item>
      <el-form-item label="真实姓名">
        <el-input v-model="ruleForm.realname"></el-input>
      </el-form-item>
      <el-form-item label="积分">
        <el-input v-model="ruleForm.integral" disabled></el-input>
      </el-form-item>
      <el-form-item label="身份证号" >
        <el-input v-model="ruleForm.idnumber"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import  qs from 'qs'
export default {

  name: "Information",
  data() {
    return {
      ruleForm: null,
      rules: {
        loginname: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]

      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var th = this
          axios({
            method:'post',
            url:'http://localhost:8082/book-manager/user/alterInformation',
            data:qs.stringify(this.ruleForm)
          }).then(function (resp){
            if(resp.data.flag=='success'){
                th.$message(resp.data.message)
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
    created() {
      var findData = {
        userId: this.$store.getters.getUser.userid
      }
      var vm = this
      axios({
        method:'get',
        url: 'http://localhost:8082/book-manager/user/findUserById?userId='+findData.userId,
        data:{
          userId: qs.stringify(findData)
        }
      }).then(function (resp){
        console.log('----------')
        console.log(resp.data)
        vm.ruleForm = resp.data
      })
    }
}
</script>

<style scoped>
  div{
    width: 700px;
    margin: 0 auto;
  }
  .el-form{
    margin-top: 100px;
  }
</style>
